Skip to content

feat: add C implementation for stats/base/ndarray/dminsorted#10134

Open
Om-A-osc wants to merge 5 commits intostdlib-js:developfrom
Om-A-osc:feat/stats-base-ndarray-dminsorted-c
Open

feat: add C implementation for stats/base/ndarray/dminsorted#10134
Om-A-osc wants to merge 5 commits intostdlib-js:developfrom
Om-A-osc:feat/stats-base-ndarray-dminsorted-c

Conversation

@Om-A-osc
Copy link
Contributor

@Om-A-osc Om-A-osc commented Feb 7, 2026


type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:

  • task: lint_filenames
    status: passed
  • task: lint_editorconfig
    status: passed
  • task: lint_markdown
    status: passed
  • task: lint_package_json
    status: passed
  • task: lint_repl_help
    status: na
  • task: lint_javascript_src
    status: passed
  • task: lint_javascript_cli
    status: na
  • task: lint_javascript_examples
    status: na
  • task: lint_javascript_tests
    status: passed
  • task: lint_javascript_benchmarks
    status: na
  • task: lint_python
    status: na
  • task: lint_r
    status: na
  • task: lint_c_src
    status: passed
  • task: lint_c_examples
    status: passed
  • task: lint_c_benchmarks
    status: passed
  • task: lint_c_tests_fixtures
    status: na
  • task: lint_shell
    status: na
  • task: lint_typescript_declarations
    status: passed
  • task: lint_typescript_tests
    status: na
  • task: lint_license_headers
    status: passed

Resolves NA

Description

This pull request adds a native C implementation for stats/base/ndarray/dminsorted.
The contribution includes C source code, native tests, benchmarks, and examples, along with updates to the C APIs section in the README. All tests and benchmarks pass successfully.

Related Issues

This pull request has the following related issues:

  • NA

Questions

No.

Other

No.

Checklist

AI Assistance

  • Yes
  • No

Disclosure

No AI assistance was used in authoring this pull request. All code, tests, benchmarks, documentation, and analysis were written manually.


@stdlib-js/reviewers

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: passed
  - task: lint_package_json
    status: passed
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: passed
  - task: lint_c_examples
    status: passed
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Feb 7, 2026
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Feb 7, 2026

Coverage Report

Package Statements Branches Functions Lines
stats/base/ndarray/dminsorted $\color{green}170/170$
$\color{green}+0.00%$
$\color{green}7/7$
$\color{green}+0.00%$
$\color{green}2/2$
$\color{green}+0.00%$
$\color{green}170/170$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
Copy link
Member

@Sachinn-64 Sachinn-64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Om-A-osc Changes are still pending in benchmark.js, test.js, and test.main.js. Refer #10039 .

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: passed
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Om-A-osc
Copy link
Contributor Author

Om-A-osc commented Feb 8, 2026

@Sachinn-64 Thank you for pointing it out. I have made the necessary changes.

@Sachinn-64
Copy link
Member

@Om-A-osc Could you address these changes here too: #10143.

@Om-A-osc
Copy link
Contributor Author

Om-A-osc commented Feb 9, 2026

@Sachinn-64 Done!

@Om-A-osc Om-A-osc requested a review from Sachinn-64 February 9, 2026 09:23
for ( i = 0; i < len; i++ ) {
data[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
}
qsort( data, len, sizeof( double ), compare );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
qsort( data, len, sizeof( double ), compare );

Same here, I don’t think we need this part.

Copy link
Contributor Author

@Om-A-osc Om-A-osc Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgryte @Sachinn-64 package expects sorted data. If we remove the sorting logic then input will be invalid. What do you suggest ?
One thing we can do is fill the array like for ( i = 0; i < len; i++ ) { x[ i ] = i; }. should i go ahead with it ?

Comment on lines 149 to 151
for ( i = 0; i < len; i++ ) {
data[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ( i = 0; i < len; i++ ) {
data[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
}

We could use a simple for loop here!

Comment on lines 96 to 115
/**
* Compares two double-precision floating-point numbers.
*
* @param a first value
* @param b second value
* @return comparison result
*/
static int compare( const void *a, const void *b ) {
const double *x = (const double *)a;
const double *y = (const double *)b;
if ( *x < *y ) {
return -1;
}
if ( *x > *y ) {
return 1;
}
return 0;
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Compares two double-precision floating-point numbers.
*
* @param a first value
* @param b second value
* @return comparison result
*/
static int compare( const void *a, const void *b ) {
const double *x = (const double *)a;
const double *y = (const double *)b;
if ( *x < *y ) {
return -1;
}
if ( *x > *y ) {
return 1;
}
return 0;
}
/**

@kgryte I don’t think this part is necessary here

@Sachinn-64 Sachinn-64 changed the title feat: add c implementation for stats/base/ndarray/dminsorted feat: add C implementation for stats/base/ndarray/dminsorted Feb 9, 2026
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: passed
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---
@Om-A-osc
Copy link
Contributor Author

Om-A-osc commented Feb 9, 2026

@Sachinn-64 I have removed the sorting code. I now use a simple for loop to fill array in sorted order in the c benchmark file.

@Om-A-osc Om-A-osc requested a review from Sachinn-64 February 9, 2026 18:29
@Sachinn-64
Copy link
Member

For now, aside from the C benchmarks, this PR looks good. Let’s see what Athan suggests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants